package com.obrock;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

/**
 * Created with IntelliJ IDEA.
 * User: Rick
 * Date: 21.10.12
 * Time: 12:19
 * To change this template use File | Settings | File Templates.
 */
public class SyncService extends Service {
    private final IBinder mBinder = new SyncServiceBinder();
    public static final Object stopService = new Object();
    public static final Object dataShare = new Object();
    public static Database db = null;

    private MessageThread messageThread = null;
    private DropboxThread dropboxThread = null;

    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        db = new Database(getApplicationContext());


        messageThread = new MessageThread(getApplicationContext());
        dropboxThread = new DropboxThread(getApplicationContext());

        if (getSharedPreferences(Main.PREFERENCES_NAME, 0).getBoolean("SYNC_ENABLE", false)) {
            DropboxThread.enable();
            DropboxThread.force();
        } else {
            DropboxThread.disable();
        }

        if (getSharedPreferences(Main.PREFERENCES_NAME, 0).getBoolean("SMS_ENABLE", false)) {
            MessageThread.enable();
            MessageThread.force();
        } else {
            MessageThread.disable();
        }

        /*
        try {
            synchronized (stopService) {
                stopService.wait();
            }
        } catch (InterruptedException e) {
            //
        }
        */

        return Service.START_STICKY;
    }


    public class SyncServiceBinder extends Binder {
        SyncService getService() {
            return SyncService.this;
        }
    }

}

